/**
 * 
 */
package actions;

import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import org.primefaces.event.FlowEvent;

import dao.DAOFactory;
import beans.Aluno;
import br.com.sigcoap.interfaces.IAlunoDao;

/**
 * @author Rafael
 * 
 */
@SessionScoped
@ManagedBean(name = "cadastroAlunoAction")
public class CadastroAlunoAction implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private boolean skip;
	 
	private Aluno aluno = new Aluno();
	
	public Aluno getAluno() {
		return aluno;
	}

	public void setAluno(Aluno aluno) {
		this.aluno = aluno;
	}
	
	public void salvar(){
		IAlunoDao alunoDao = DAOFactory.getInstance().getAlunoDao();
		try {
			
			alunoDao.beginTransaction();
			alunoDao.save(getAluno());
			alunoDao.commitTransaction();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			alunoDao.rollback();
		}
	}
	
    public String onFlowProcess(FlowEvent event) {
        if(skip) {
            skip = false;   //reset in case user goes back
            return "confirm";
        }
        else {
            return event.getNewStep();
        }
    }

}
